package com.zk.demo.util;

import lombok.Data;

/**
 * @author chengtianping
 * @description 返回结果封装
 */
@Data
public class ResultResponse<T> {


    private Integer code;

    private String message;

    private Object data;

    private Integer count;

    public ResultResponse() {
    }

    public ResultResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * layui特定分页返回
     * @param code
     * @param message
     * @param totalCount
     */
    public ResultResponse(Integer code, String message, Integer totalCount, T data) {
        this.code = code;
        this.message = message;
        this.count=totalCount;
        this.data = data;
    }

    public ResultResponse(T data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.message = ResultCode.SUCCESS.getDesc();
        this.data = data;
    }

    public static ResultResponse buildSuccess() {
        return new ResultResponse<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getDesc());
    }
    public static ResultResponse buildLayuiSuccess(Object data, Integer totalCount) {
        return new ResultResponse<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getDesc(), totalCount,data);
    }

    public static ResultResponse buildSuccess(Object data) {
        return new ResultResponse<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getDesc(),
                data);
    }

    public static ResultResponse buildFailed(Integer code, String message) {
        return new ResultResponse(code, message);
    }

    public static ResultResponse buildFailed() {
        return new ResultResponse(ResultCode.FAILEDADD.getCode(), ResultCode.FAILEDADD.getDesc());
    }
    public static ResultResponse buildFailed(ResultCode resultCode) {
        return new ResultResponse(resultCode.getCode(), resultCode.getDesc());
    }

    public static ResultResponse buildFailed(Integer code, String message, Object data) {
        return new ResultResponse(code, message, data);
    }
}
